package com.bbg.amyam.process.schedule.worker;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import com.bbg.amyam.domain.model.PasswordRetrieveKey;

@Component("passwordRetrieveKeyCleanupWork")
public class PasswordRetrieveKeyCleanupWork implements Worker {

	protected static Logger logger = Logger.getLogger(PasswordRetrieveKeyCleanupWork.class);
	
	@Override
	public void work() {
			String threadName = Thread.currentThread().getName();
			logger.debug("   " + threadName + " has began working.");
			Date current = new Date();
			Date stamp=new Date(current.getTime()-2*24*60*60*1000);
			
			List<PasswordRetrieveKey> keys = PasswordRetrieveKey.findPasswordRetrieveKeysByCreatedDateLessThan(stamp).getResultList();
	        for(PasswordRetrieveKey key:keys){
	        	key.remove();
	        }
	        logger.debug("   " + threadName + " has completed work.");
		
		
	}

}
